home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-06-23 | 2.3 KB | 80 lines |
- /*
- * QuickTime for Java SDK Sample Code
-
- Usage subject to restrictions in SDK License Agreement
- * Copyright: © 1996-1999 Apple Computer, Inc.
-
- */
- import java.applet.Applet;
- import java.awt.*;
- import java.awt.event.*;
-
- import quicktime.*;
- import quicktime.io.QTFile;
-
- import quicktime.app.QTFactory;
- import quicktime.app.display.*;
- import quicktime.app.image.ImageDrawer; // for exceptions
-
- public class QTStreamingApplet extends Applet {
- private Drawable myQTContent;
- private QTCanvas myQTCanvas;
-
- public void init () {
- try {
- QTSession.open();
- // set up a QTCanvas which will disply its content
- // at its original size of smaller and centered in the space given
- // to the QTCanvas when the applet is layed out
- setLayout (new BorderLayout());
- myQTCanvas = new QTCanvas (QTCanvas.kInitialSize, 0.5F, 0.5F);
- add (myQTCanvas, "Center");
-
- myQTContent = ImageDrawer.getQTLogo();
-
- final TextField urlTextField = new TextField ("file:///... Enter an URL to a movie", 30);//Enter URL to movie here", 30);
- urlTextField.setFont (new Font ("Dialog", Font.PLAIN, 10));
- urlTextField.setEditable (true);
- urlTextField.addActionListener (new ActionListener () {
- TextField tf = urlTextField;
-
- public void actionPerformed (ActionEvent ae) {
- if (myQTCanvas != null) {
- try {
- //tf.getText() returns the URL the user has entered
- myQTContent = QTFactory.makeDrawable (tf.getText());
- myQTCanvas.setClient (myQTContent, true);
- } catch (QTException e) {
- //probably a non-fatal error that the Applet
- //should deal with more informatively
- e.printStackTrace();
- }
- }
- }
- });
- add (urlTextField, "South");
- } catch (QTException qtE) {
- //in this case the only QTException is in QTSession.open()
- throw new RuntimeException (qtE.getMessage());
- }
- }
-
- public void start () {
- try { // if QT was not successfully initialized the QTCanvas will be null
- if (myQTCanvas != null)
- myQTCanvas.setClient (myQTContent, true);
- } catch (QTException e) {
- e.printStackTrace();
- }
- }
-
- public void stop () {
- if (myQTCanvas != null)
- myQTCanvas.removeClient();
- }
-
- public void destroy () {
- QTSession.close();
- }
- }
-